<?php

namespace console\controllers;

use common\models\Course;
use common\utils\Utils;
use Yii;
use yii\db\Migration;

/**
 * 文件i控制台程序
 * Class FileController
 */
class CourseController extends \yii\console\Controller
{
    /**
     * @name: actionSeeder 填充课程数据
     * @return void
     * @author: 朱晓进  Storm <qhj1989@qq.com>
     */
    public function actionSeeder()
    {
        $faker = \Faker\Factory::create('zh_CN');
        $a = 0;
        for ($i = 0; $i < 20; $i++) {
            $course = new Course();
            $course->id=Utils::uniqueKey();
            $course->title = $faker->word;
            $course->intro=$faker->paragraph();
            $course->user_id = rand(1, 20);
            $course->created_at = time();
            $course->updated_at = time()+724000;
            if ($course->insert()) {
                $a += 1;
            } else {
                print_r($course->errors) ;
            }
        }
        echo "添加" . $a . "条数据";
    }
}